package se.webbzon.boltzmann.battle.battleaction.buffdamage;

import java.util.List;

import se.webbzon.boltzmann.battle.battleaction.BattleAction;
import se.webbzon.boltzmann.battle.object.npc.BattleNPC;
import se.webbzon.boltzmann.battle.property.BattleBuffType;
import se.webbzon.boltzmann.effect.AcidEffect;
import se.webbzon.boltzmann.effect.CharacterDamageEffect;
import se.webbzon.boltzmann.effect.Effect;
import se.webbzon.boltzmann.effect.ExplosionEffect;
import se.webbzon.boltzmann.effect.FrostEffect;
import se.webbzon.boltzmann.game.npc.StandingDuty;
import se.webbzon.boltzmann.timer.Timer;
import se.webbzon.boltzmann.timer.TimerListener;
import se.webbzon.oschi01.worldarea.WorldArea;

public class BuffDamageAction extends BattleAction implements TimerListener {
	
	// The buff type causing the damage
	private final BattleBuffType type;
	
	/*============================================================
	Constructors
	============================================================*/

	/** Creates a new buff damage action of a given type. **/
	public BuffDamageAction(WorldArea world,
							BattleNPC caster, 
							List<BattleNPC> targets, 
							BattleBuffType type) {
		super(world, caster, targets);
		this.type = type;
	}
	
	/*============================================================
	Public Methods
	============================================================*/
	
	@Override public void onBegin() {
		BattleNPC target = getTargets().get(0);
		target.assignDuty(new StandingDuty(target));
		
		damage(target,1);
		
		Timer timer = new Timer(45);
		timer.addListener(this);
		timer.start(getWorld());
	}
	
	@Override public void onEnd() {};

	@Override public void onAlarm(Timer timer) {
		end();
	}

	@Override public void onAbsorb(BattleNPC target) {

	}

	@Override public void onDamage(BattleNPC target) {
		Effect damage = new CharacterDamageEffect(target,30);
		damage.launch(getWorld());
		Effect buff = null;
		if (type == BattleBuffType.ACID)
			buff = new AcidEffect(target);
		else if (type == BattleBuffType.FROST)
			buff = new FrostEffect(target,true);
		else
			buff = new ExplosionEffect(target);
		buff.launch(getWorld());
	}

	@Override public void onHeal(BattleNPC target) {

	}

}
